/**
 * 
 * Description: 
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Apr 8, 2009 2:27:19 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.poi;

import java.io.OutputStream;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.paradise.dms.pojo.Student;

/**
 * 
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Apr 8, 2009 2:27:19 PM 李萌（neolimeng@gmail.com）created
 */
public class StudentPoi {
	private PoiUtil poiUtil;
	private String[] studentTitleRowValues = { "aaa", "bbb", "ccc" };
	private HSSFWorkbook workbook;
	private HSSFSheet sheet;
	private HSSFRow row;
	@SuppressWarnings("unused")
	private HSSFCell cell;

	public StudentPoi() {
		this.poiUtil = new PoiUtil();
	}

	/**
	 * 
	 * Description: Write students into an Excel file.
	 * 
	 * List<Student> contains the students to be written to the Excel file.
	 * 
	 * OutputStream specifies the output stream to write.
	 * 
	 * @Version1.0 Apr 23, 2009 2:28:53 AM 李萌（neolimeng@gmail.com）创建
	 * @param sl
	 * @param os
	 */
	public void writeStudentExcel(List<Student> sl, OutputStream os) {
		this.poiUtil.init("studentExcel.xls", "studentsheet");
		this.workbook = poiUtil.getWorkbook();
		this.sheet = poiUtil.getSheet();
		// 创建标题行
		this.poiUtil.poiCreateTitleRow(studentTitleRowValues);
		// 创建内容
		for (int i = 0; i < sl.size(); i++) {// 行循环
			this.row = this.sheet.createRow(i + 1);
			this.row.createCell(0).setCellValue(sl.get(i).getStudentno().toString());
			this.row.createCell(1).setCellValue(sl.get(i).getStudentname().toString());
			this.row.createCell(2).setCellValue(sl.get(i).getStudentgender().toString());
		}
		this.poiUtil.poiWriteExcel(this.workbook, os);
	}

	/**
	 * 
	 * Description: 将学生基本信息写入Excel
	 * 
	 * @Version1.0 Apr 30, 2009 1:05:14 AM Neo
	 * @param list
	 * @param os
	 */

	@SuppressWarnings("unchecked")
	public void writeSelectedStudentsBasicInfoToExcel(List list, OutputStream os) {
		this.poiUtil.init("studentExcel.xls", "studentsheet");
		this.workbook = poiUtil.getWorkbook();
		this.sheet = poiUtil.getSheet();
		// 创建标题行
		this.poiUtil.poiCreateTitleRow(studentTitleRowValues);
		for (int i = 0; i < list.size(); i++) {
			this.row = this.sheet.createRow(i + 1);
			Object[] obj = (Object[]) list.get(i);
			this.row.createCell(0).setCellValue(obj[0].toString());
			this.row.createCell(1).setCellValue(obj[1].toString());
			this.row.createCell(2).setCellValue(obj[2].toString());
		}
		this.poiUtil.poiWriteExcel(this.workbook, os);
	}
}
